Route subagents on the spawn message when plaintext at PreToolUse - #266
Merged
Conversation
The subagent-routing hook now reads `tool_input.message` (the actual task content) as the routing task when it's a plaintext string at PreToolUse time. Codex encrypts the message at send-time, but the hook fires before that — so if the message is readable here, the router gets real task signal instead of the generic "Codex subagent task" fallback (which always returned the default arm). When `message` is an encrypted dict (or absent), routing falls through to `task_name` / `agent_name` as before — no regression. The field-selection logic uses `isinstance(str)` so non-string values (encrypted dicts) are skipped cleanly. Co-authored-by: Isaac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Codex subagent smart routing was effectively inert: the routing hook read
task_name(a path label liketask_3) or fell back to the generic"Codex subagent task"string, giving thetask_v1router no task signal — so it always returned the default arm (gpt-5-6-sol).The actual task content lives in
tool_input.message, which is plaintext atPreToolUsetime (Codex encrypts it at send-time, but the hook fires before that). This was confirmed empirically by capturing a real spawn payload:The fix
route_spawn_toolnow readsmessagefirst (when it's a plaintext string), falling back totask_name/agent_name(weaker labels) then the generic default. Theisinstance(str)filter means encrypted dicts (if they ever appear) skip cleanly — no regression.How do you know it works
test_spawn_routes_on_plaintext_message_when_present(verifies the router receives the real message text),test_spawn_falls_through_encrypted_message_to_task_name(verifies encrypted dicts fall through, no regression).messagein theshortlength bucket (400–1200) — exactly wheretask_v1can differentiate between arms, instead of the contentless fallback that always returned the default.This is a follow-up to #251 (codex smart routing, merged) and #255 (claude smart routing, merged).
This pull request and its description were written by Isaac.